package com.etbsms.domain;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.etbsms.form.AgricultureAndFoodForm;


@Entity
@Table(name = "Etbsms_AgricultureAndFood")
public class AgricultureAndFood implements Serializable {
	
	public AgricultureAndFood(){}
	
	public AgricultureAndFood(AgricultureAndFoodForm form){
		this.rec_no = form.getRec_no();
		this.title_o = form.getTitle_o();	
		this.title_c = form.getTitle_c();	
		this.author = form.getAuthor();	
		this.affiliation = form.getAffiliation();			
		this.publisher = form.getPublisher();			
		this.journal = form.getJournal();				
		this.vol_page = form.getVol_page();	
		this.year = form.getYear();		
		this.doc_type = form.getDoc_type();	
		this.abstract_o = form.getAbstract_o();	
		this.abstract_c = form.getAbstract_c();	
		this.keyword_o = form.getKeyword_o();	
		this.keyword_c = form.getKeyword_c();	
		this.url = form.getUrl();	
		this.clazz = form.getClazz();							
		this.citation_title = form.getCitation_title();	
		this.citation_author = form.getCitation_author();	
		this.citation_source = form.getCitation_source();		
		this.created = form.getCreated();
		this.analyzed = form.isAnalyzed();		
		this.literature = form.getLiterature();
		this.literature_desc = form.getLiterature_desc();
		this.flow = form.getFlow();	
	}
	
	public void update(AgricultureAndFoodForm form){
		this.title_o = form.getTitle_o();	
		this.title_c = form.getTitle_c();	
		this.author = form.getAuthor();	
		this.affiliation = form.getAffiliation();			
		this.publisher = form.getPublisher();			
		this.journal = form.getJournal();				
		this.vol_page = form.getVol_page();	
		this.year = form.getYear();		
		this.doc_type = form.getDoc_type();	
		this.abstract_o = form.getAbstract_o();	
		this.abstract_c = form.getAbstract_c();	
		this.keyword_o = form.getKeyword_o();	
		this.keyword_c = form.getKeyword_c();	
		this.url = form.getUrl();	
		this.clazz = form.getClazz();							
		this.citation_title = form.getCitation_title();	
		this.citation_author = form.getCitation_author();	
		this.citation_source = form.getCitation_source();		
		this.analyzed = form.isAnalyzed();		
		this.flow = form.getFlow();
		this.literature = form.getLiterature();
		this.literature_desc = form.getLiterature_desc();
	}	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -2529843096925657568L;

	private int seq_no;
	private String rec_no;
	private String title_o;	
	private String title_c;	
	private String author;	
	private String affiliation;				/** 作者服務機構**/
	private String publisher;					/** 出版機構**/
	private String journal;						/** 期刊名稱**/
	private String vol_page;	
	private Integer year;	
	private CodeLanguage language;	
	private Set<CodeCountry> countries = new HashSet<CodeCountry>();
	private Set<CodePlant> plants = new HashSet<CodePlant>();	
	private String doc_type;	
	private String abstract_o;	
	private String abstract_c;	
	private String keyword_o;	
	private String keyword_c;	
	private String url;	
	private String clazz;							/** 主題分類**/
	private String citation_title;			/** 被引標題**/
	private String citation_author;		/** 被引作者**/
	private String citation_source;		/** 被引出處**/	
	private boolean analyzed;					/** 是否研析**/
	private Set<Files> files = new HashSet<Files>();
	
	/** 目前流程
	 * 0,暫存
	 * 1,輸入完成
	 * 2,輸入檢核完成
	 */
	private Integer flow;
	private Date created;
	private Date updated;
	private Users users;
	private ResearchAndAnalysis researchAndAnalysis;
	

	/** 2011/11/23 新增欄位 **/	
	private Integer literature;							/** 文獻性質**/
	private String literature_desc;				/** 文獻性質_其它說明**/
	private boolean temporary = false;		/** 用來暫存表單記錄**/
	
	/*************************/
	
	/** 2011/11/20 新增欄位 **/
//	private boolean enabled;
//	private Users updated_user;
	/*************************/
	
	@Id 
	@Column(name = "seq_no" ,nullable = false)
	@GeneratedValue(generator = "paymentableGenerator")       
	@GenericGenerator(name = "paymentableGenerator", strategy = "identity")
	public int getSeq_no() {
		return seq_no;
	}
	public void setSeq_no(int seq_no) {
		this.seq_no = seq_no;
	}
	
	@Column(nullable = true ,length = 32)
	public String getRec_no() {
		return rec_no;
	}
	public void setRec_no(String rec_no) {
		this.rec_no = rec_no;
	}
	
	@Column(nullable = true ,length = 1024)
	public String getTitle_o() {
		return title_o;
	}
	public void setTitle_o(String title_o) {
		this.title_o = title_o;
	}
	
	@Column(nullable = true ,length = 1024)
	public String getTitle_c() {
		return title_c;
	}
	public void setTitle_c(String title_c) {
		this.title_c = title_c;
	}
	
	@Column(nullable = true ,length = 1024)
	public String getAuthor() {
		return author;
	}
	public void setAuthor(String author) {
		this.author = author;
	}
	
	@Column(nullable = true ,length = 1024)
	public String getPublisher() {
		return publisher;
	}
	public void setPublisher(String publisher) {
		this.publisher = publisher;
	}
	
	@Column(nullable = true ,length = 1024)
	public String getJournal() {
		return journal;
	}
	public void setJournal(String journal) {
		this.journal = journal;
	}
	
	@Column(nullable = true ,length = 512)
	public String getVol_page() {
		return vol_page;
	}
	public void setVol_page(String vol_page) {
		this.vol_page = vol_page;
	}
	
	@Column(nullable = true)
	public Integer getYear() {
		return year;
	}
	public void setYear(Integer year) {
		this.year = year;
	}
	
	@ManyToOne
	@JoinColumn(name="CodeLanguage_seqNo")
	public CodeLanguage getLanguage() {
		return language;
	}
	public void setLanguage(CodeLanguage language) {
		this.language = language;
	}
	
	@ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.LAZY,targetEntity=CodeCountry.class)
	@JoinTable(name="Etbsms_AgricultureAndFood_CodeCountry",
		joinColumns={@JoinColumn(name="agricultureAndFood_seqNo")},
		inverseJoinColumns={@JoinColumn(name="codeCountry_seqNo")})
	public Set<CodeCountry> getCountries() {
		return countries;
	}
	public void setCountries(Set<CodeCountry> countries) {
		this.countries = countries;
	}
	
	@ManyToMany(cascade={CascadeType.ALL},fetch=FetchType.LAZY,targetEntity=CodePlant.class)
	@JoinTable(name="Etbsms_AgricultureAndFood_CodePlant",
		joinColumns={@JoinColumn(name="agricultureAndFood_seqNo")},
		inverseJoinColumns={@JoinColumn(name="codePlant_seqNo")})
	public Set<CodePlant> getPlants() {
		return plants;
	}
	public void setPlants(Set<CodePlant> plants) {
		this.plants = plants;
	}
	
	
	@Column(nullable = true ,length = 12)
	public String getDoc_type() {
		return doc_type;
	}
	public void setDoc_type(String doc_type) {
		this.doc_type = doc_type;
	}
	
	@Column(nullable = true ,length = 4096)
	public String getAbstract_o() {
		return abstract_o;
	}
	public void setAbstract_o(String abstract_o) {
		this.abstract_o = abstract_o;
	}
	
	@Column(nullable = true ,length = 4096)
	public String getAbstract_c() {
		return abstract_c;
	}
	public void setAbstract_c(String abstract_c) {
		this.abstract_c = abstract_c;
	}
	
	@Column(nullable = true ,length = 1024)
	public String getKeyword_o() {
		return keyword_o;
	}
	public void setKeyword_o(String keyword_o) {
		this.keyword_o = keyword_o;
	}
	
	@Column(nullable = true ,length = 1024)
	public String getKeyword_c() {
		return keyword_c;
	}
	public void setKeyword_c(String keyword_c) {
		this.keyword_c = keyword_c;
	}
	
	@Column(nullable = true ,length = 1024)
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	
	@Column(nullable = true ,length = 12)
	public String getClazz() {	
		return clazz;
	}
	public void setClazz(String clazz) {
		this.clazz = clazz;
	}
	
	@Column(nullable = true ,length = 4000)
	public String getAffiliation() {
		return affiliation;
	}
	public void setAffiliation(String affiliation) {
		this.affiliation = affiliation;
	}
	
	@Column(nullable = true ,length = 4000)
	public String getCitation_title() {
		return citation_title;
	}
	public void setCitation_title(String citation_title) {
		this.citation_title = citation_title;
	}
	
	@Column(nullable = true ,length = 4000)
	public String getCitation_author() {
		return citation_author;
	}
	public void setCitation_author(String citation_author) {
		this.citation_author = citation_author;
	}
	
	@Column(nullable = true ,length = 4000)
	public String getCitation_source() {
		return citation_source;
	}
	public void setCitation_source(String citation_source) {
		this.citation_source = citation_source;
	}
	
	@Column(nullable = false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreated() {
		return created;
	}
	public void setCreated(Date created) {
		this.created = created;
	}
	
	@Column(nullable = true)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getUpdated() {
		return updated;
	}
	public void setUpdated(Date updated) {
		this.updated = updated;
	}
	
	@ManyToOne
	@JoinColumn(name="Users_seqNo")
	public Users getUsers() {
		return users;
	}
	public void setUsers(Users users) {
		this.users = users;
	}
	
	@Column(nullable = false)
	public boolean isAnalyzed() {
		return analyzed;
	}
	public void setAnalyzed(boolean analyzed) {
		this.analyzed = analyzed;
	}

	@Column(nullable = false)
	public Integer getFlow() {
		return flow;
	}

	public void setFlow(Integer flow) {
		this.flow = flow;
	}

	@ManyToMany(cascade={CascadeType.ALL})
	@JoinTable(name="Etbsms_AgricultureAndFood_Files",
		joinColumns={@JoinColumn(name="agricultureAndFood_seqNo")},
		inverseJoinColumns={@JoinColumn(name="files_seqNo")})
	public Set<Files> getFiles() {
		return files;
	}
	public void setFiles(Set<Files> files) {
		this.files = files;
	}
	
	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="ResearchAndAnalysis_SerialNumber",nullable=true,insertable=true)
	public ResearchAndAnalysis getResearchAndAnalysis() {
		return researchAndAnalysis;
	}
	public void setResearchAndAnalysis(ResearchAndAnalysis researchAndAnalysis) {
		this.researchAndAnalysis = researchAndAnalysis;
	}
	
	@Column(nullable = true)
	public Integer getLiterature() {
		return literature;
	}

	public void setLiterature(Integer literature) {
		this.literature = literature;
	}	

	@Column(nullable = true ,length = 64)
	public String getLiterature_desc() {
		return literature_desc;
	}

	public void setLiterature_desc(String literature_desc) {
		this.literature_desc = literature_desc;
	}

	@Column(nullable = false)
	public boolean isTemporary() {
		return temporary;
	}

	public void setTemporary(boolean temporary) {
		this.temporary = temporary;
	}
}
